/* 
Set directory 
*/

    global root ENTER DIRECTORY

	global r4oc 		$root\Data\Young Lives\R4\UKDA-7931-stata11\stata11\india_r4\oc_hh_anon
	global r4yc 		$root\Data\Young Lives\R4\UKDA-7931-stata11\stata11\india_r4\yc_ch_anon
	global r3oc 		$root\Data\Young Lives\R3\survey_data_r3\india_r3\olderchild
	global r3yc 		$root\Data\Young Lives\R3\survey_data_r3\india_r3\youngerchild
	global r2oc 		$root\Data\Young Lives\R2\survey_data_r2\india_r2\Older Child
	global r2yc 		$root\Data\Young Lives\R2\survey_data_r2\india_r2\Younger Child

	global data 		$root\Dta\Young Lives\
	
	
use "$r2oc\inchildquest12yrold.dta", clear

keep MISSCH WMISSC1 WMISSC2 WMISSC3 CHILDID	

gen absent = 0 
replace absent = 1 if MISSCH == 1

gen sick_ab = 0
replace sick_ab = 1 if WMISSC1 == 16 | WMISSC2 == 16 | WMISSC3 == 16

keep CHILDID absent sick_ab

gen round = 2

save "$data\r2oc_attend.dta", replace


use "$r3oc\in_oc_childlevel.dta", clear

keep CHILDID WMISSCR3  MISSCHR3

gen absent = 0 
replace absent = 1 if MISSCHR3 == 1

gen sick_ab = 0
replace sick_ab = 1 if WMISSCR3 == 16 

keep CHILDID absent sick_ab

gen round = 3

save "$data\r3oc_attend.dta", replace

use "$r3yc\in_yc_childlevel.dta", clear


keep CHILDID MSSDSCR3 SCWHYR31 SCWHYR32 SCWHYR33

gen absent = 0 
replace absent = 1 if MSSDSCR3 == 1

gen sick_ab = 0
replace sick_ab = 1 if SCWHYR31 == 16 | SCWHYR32 == 16 | SCWHYR33 == 16

keep CHILDID absent sick_ab

gen round = 3

append using "$data\r3oc_attend.dta"

save "$data\r3_attend.dta", replace


use "$r4yc\in_r4_ycch_youngerchild", clear

keep CHILDCODE MISSCHR4 WMSSCR41 WMSSCR42 WMSSCR43

gen absent = 0 
replace absent = 1 if MISSCHR4 == 1

gen sick_ab = 0
replace sick_ab = 1 if WMSSCR41 == 16 | WMSSCR42 == 16 | WMSSCR43 == 16

keep CHILDCODE absent sick_ab

gen round = 5

save "$data\r4yc_attend.dta", replace

append using "$data\r3_attend.dta"
append using "$data\r2oc_attend.dta"

gen temp = 0
egen temp1 = concat(temp CHILDCODE) if CHILDCODE < 100000
tostring CHILDCODE, replace
replace temp1 = CHILDCODE if temp1 == ""
drop temp
gen temp = "IN"
egen temp2 = concat(temp temp1)
replace CHILDID = temp2 if round == 5
drop temp* CHILDCODE

ren CHILDID childid

save "$data\attend.dta", replace
